package org.jtzc.springaifunction.config;

import org.jtzc.springaifunction.fun.CurrentTimeFun;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackWrapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

@Configuration
public class CalculatorService {
    public record AddOperation(int a, int b) {

    }

    public record MulOperation(int m, int n) {

    }

    //注册
    @Bean
    @Description("加法运算")
    public Function<AddOperation,Integer> addOperation() {
        System.out.println("加法运算");
        return request -> {
            return request.a + request.b;
        };
    }

    @Bean
    @Description("乘法运算")
    public Function<MulOperation,Integer> mulOperation() {
        System.out.println("乘法运算");
        return request -> {
            return request.m * request.n;
        };
    }

    @Bean
    public FunctionCallback currentTimeFun() {
        return FunctionCallbackWrapper.builder(new CurrentTimeFun())
                .withName("currentTime") // (1) 函数名称
                .withDescription("Get the current time in location") // (2) 函数描述
                .build();
    }
}
